package com.speakglobe.admin.service;

import com.speakglobe.admin.dao.SystemPropertyDao;
import com.speakglobe.admin.model.SystemProperty;
import com.speakglobe.util.ParamUtil;

public class AdminServiceImpl implements AdminService {

	private SystemPropertyDao systemPropertyDao;
	
	
	public void setSystemPropertyDao(SystemPropertyDao systemPropertyDao) {
		this.systemPropertyDao = systemPropertyDao;
	}

	@Override
	public String getValueForSystemProperty(String key) {
		String value = null;
		SystemProperty property = this.getSystemProperty(key);
		
		if(property!=null){
			value = property.getValue();
		}
		
		return value;
	}

	@Override
	public double getDoubleValueForSystemProperty(String key) {
		double value = 0;
		
		SystemProperty property = this.getSystemProperty(key);
		
		if(property != null && ParamUtil.isDouble(property.getValue())) {
			value = Double.parseDouble(property.getValue());
		}
		
		return value;
	}

	@Override
	public int getIntegerValueForSystemProperty(String key) {
		int value = 0;
		SystemProperty property = this.getSystemProperty(key);
		
		if(property != null && ParamUtil.isInt(property.getValue())) {
			value = Integer.parseInt(property.getValue());
		}
		
		return value;
	}
	
	private SystemProperty getSystemProperty(String key) {
		return systemPropertyDao.findByKey(key);
	}

}
